-
Notifications
You must be signed in to change notification settings - Fork 149
New API to observe user input #590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
03459d7
to
9a44d9a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new InputObserving API to capture and forward user input events in a more flexible and unified way across touch, pointer, and keyboard interactions. Key changes include the implementation of new protocols (InputObserving, InputObservable) and adapters (InputObservingGestureRecognizerAdapter), refactoring of legacy input callbacks in navigator view controllers, and corresponding updates in related JavaScript files for key and pointer events.
Reviewed Changes
Copilot reviewed 40 out of 41 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
Sources/Navigator/Input/Key/Key.swift | Added Key enum with support for various key types and helper properties. |
Sources/Navigator/Input/InputObserving*.swift | Introduced new interfaces and implementations for observing input events. |
Sources/Navigator/EPUB/* | Updated EPUB view controllers to utilize the new InputObserving API and removed legacy tap/press handlers. |
Sources/Navigator/DirectionalNavigationAdapter.swift | Migrated to use the new bind(to:) pattern, deprecating old methods. |
Sources/Navigator/EPUB/Scripts/src/*.js | Replaced deprecated key event messaging with sendKeyEvent calls and added pointer event listeners. |
Others | Package and changelog updates reflecting dependency bumps and the new API introduction. |
Files not reviewed (1)
- Sources/Navigator/EPUB/Scripts/pnpm-lock.yaml: Language not supported
Changelog
Added
Navigator
InputObserving
API has been added to enable more flexible gesture recognition and support for mouse pointers.User guide
In visual publications like EPUB or PDF, users can interact with the
VisualNavigator
instance using gestures, a keyboard, a mouse, a pencil, or a trackpad. When the publication does not override user input events, you may want to intercept them to trigger actions in your user interface. For example, you can turn pages or toggle the navigation bar on taps, or open a bookmarks screen when pressing the Command-Shift-D hotkey.VisualNavigator
implementsInputObservable
, providing a way to intercept input events.Implementing an input observer
Here's an example of a simple
InputObserving
implementation that logs all key and pointer events emitted by the navigator.If you choose to handle a specific event, return
true
to prevent subsequent observers from using it. This is useful when you want to avoid triggering multiple actions upon receiving an event.An
InputObserving
implementation receives low-level events that can be used to create higher-level gesture recognizers, such as taps or pinches. To assist you, the toolkit also offers helpers to observe tap, click and key press events.Observing tap and click events
The
ActivatePointerObserver
is an implementation ofInputObserving
recognizing single taps or clicks. You can use the convenient static factories to observe these events.Observing keyboard events
Similarly, the
KeyboardObserver
implementation provides an easy method to intercept keyboard events.It can also be used to observe a specific keyboard shortcut.
Migration guide
The
DirectionalNavigationAdapter
was also updated to use this new API, and is easier to use.To migrate the old API, remove the old
VisualNavigatorDelegate
callbacks, for example:Instead, setup your observers after initializing the navigator. Return
true
if you want to stop the propagation of a particular event to the next observers.